﻿//
// Copyright (c) 2024 BPergaofeng
//

#include <bperplayer/BPerPlayerPlay.h>
#include <bperplayer/BPerPlayFactory.h>

#include <bperutil/sys/BPerLog.h>
#include <bperaudiodev/android/BPerAudioPlayAndroid.h>

BPerPlayerPlay::BPerPlayerPlay() {
	m_audioPlay=NULL;
	vm_audio_player_start=0;
}

BPerPlayerPlay::~BPerPlayerPlay() {
    bPer_stop(m_audioPlay);
    bPer_stop_thread(m_audioPlay);

}
void BPerPlayerPlay::stopAll(){
	if(m_audioPlay)	m_audioPlay->stop();

}
void BPerPlayerPlay::initAudioPlay(BPerContext* paudio){

	if (m_audioPlay == NULL) {
#if BPer_OS_WIN
    m_audioPlay = new BPerWinAudioApiRender(&paudio->avinfo,&paudio->synMgr);
#else
#if BPer_OS_ANDROID
    m_audioPlay = new BPerAudioPlayAndroid(&paudio->avinfo,&paudio->synMgr);
#else
        #if BPer_OS_APPLE
            m_audioPlay = new BPerAudioPlayMac(&paudio->avinfo,&paudio->synMgr);
        #else
            m_audioPlay = new BPerAudioPlayLinux(&paudio->avinfo,&paudio->synMgr);
        #endif
#endif
#endif
		m_audioPlay->init();

	}

}

void BPerPlayerPlay::startAudioPlay(){

	if(vm_audio_player_start) return;

	m_audioPlay->start();
	vm_audio_player_start=1;
}
void BPerPlayerPlay::setInAudioList(BPerAudioPlayBuffer *paudioList){
	if(m_audioPlay!=NULL) m_audioPlay->setAudioBuffer(paudioList);
}

